﻿using AutoMapper;
using Common.Communal;
using ERP.Domain.SalesManagement;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sell.Api.Write.Application.Command.SalesManagementCommand;

namespace Sell.Api.Write.Controllers.SalesManagement
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class VerificationController : ControllerBase
    {
        private readonly IMediator mediator;
        public VerificationController(IMediator _mediator)
        {
            mediator = _mediator;
        }
        /// <summary>
        /// 采购核价添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<ApiResult<int>> VerificationAdd(VerificationAddCommand request)
        {
           return await mediator.Send(request);
        }
        /// <summary>
        /// 采购核价删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<ApiResult<int>> VerificationDel([FromQuery]VerificationDelCommand request)
        {
           return await mediator.Send(request);
        }
        /// <summary>
        /// 采购核价修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<ApiResult<int>> VerificationUpdate([FromBody] VerificationUpdatelCommand request)
        {
            if (!ModelState.IsValid)
            {
                var result = new ApiResult<int>();
                result.Error("请求参数验证失败");
                return result;
            }
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改采购核价审核状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> VerificationUpdateReviewStatus([FromBody] VerificationUpdateReviewStatusCommand request)
        {
            if (!ModelState.IsValid)
            {
                var result = new ApiResult<int>();
                result.Error("请求参数验证失败");
                return result;
            }
            return await mediator.Send(request);
        }
    }
}
